using System;
using System.Collections.Generic;

namespace Baula.TextGen.ActiveTemplating
{
    public class DefaultContext
    {
        private readonly IDictionary<ProcedureType, string> _codeForProcedureTypes
            = new Dictionary<ProcedureType, string>
              {
                  {ProcedureType.Undefined, "*** ProcedureType is undefined ***"},
                  {ProcedureType.Sub, "Sub"},
                  {ProcedureType.Function, "Function"},
                  {ProcedureType.Property, "Property"}
              };

        private readonly IDictionary<ModuleType, string> _codeForModuleTypes
            = new Dictionary<ModuleType, string>
              {
                  {ModuleType.Undefined, "*** ModuleType is undefined ***"},
                  {ModuleType.Module, "Module"},
                  {ModuleType.Class, "Class"},
                  {ModuleType.VbaDocument, "Vba Document"}
              };

        public virtual string ProjectName { get; set; }
        public virtual string ProcedureName { get; set; }
        public virtual string ModuleName { get; set; }
        public string Author { get; set; }
        public DateTime CurrentDate { get; set; }
        public string CurrentDateAsString { get { return CurrentDate.ToString(); } }
        public DateTime CurrentTime { get; set; }
        public string CurrentTimeAsString { get { return CurrentTime.ToString(); } }
        public ModuleType ModuleType { get; set; }
        public string ModuleTypeAsString { get { return GetModuleTypeForCode(ModuleType); } }
        public string ReturnType { get; set; }
        public string ReturnTypePrefix { get; set; }
        public ProcedureType ProcedureType { get; set; }
        public string ProcedureTypeAsString { get { return GetProcedureTypeForCode(ProcedureType); } }

        private string GetModuleTypeForCode(ModuleType moduleType)
        {
            if (!_codeForModuleTypes.ContainsKey(moduleType))
                throw new ArgumentOutOfRangeException("moduleType");

            return _codeForModuleTypes[moduleType];
        }

        private string GetProcedureTypeForCode(ProcedureType procedureType)
        {
            if (!_codeForProcedureTypes.ContainsKey(procedureType))
                throw new ArgumentOutOfRangeException("procedureType");

            return _codeForProcedureTypes[procedureType];
        }
    }
}